﻿// -----------------------------------------------------------------------
// <copyright file="NamePointCut.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Raop.Library.Aop.PointCut
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Roslyn.Compilers.CSharp;
    using Raop.Library.Tools;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class NamePointCut : VisitorBasePointCut
    {
        protected override Roslyn.Compilers.CSharp.SyntaxNode VisitMethodDeclaration(Roslyn.Compilers.CSharp.MethodDeclarationSyntax node)
        {
            if (node.BodyOpt != null)
            {
                var block = node.BodyOpt;

                var s = this.model.GetDeclaredSymbol(node);
                var collection = this.compil.FindNamedTypeSymboles(n => Inherit<BaseAopMethodName>(n));

                foreach (var item in collection)
                {
                    block = AddAop(item.Name, s.ContainingType.Name, s.Name, block);
                }

                //foreach (var att in s.GetAttributes())
                //{
                //    if (Inherit<BaseAopAttribute>(att.AttributeClass))
                //    {
                //        block = AddAop(att.AttributeClass.Name, s.ContainingType.Name, s.Name, block);
                //    }
                //}

                node = node.ReplaceNode(node.BodyOpt, block);
            }

            return base.VisitMethodDeclaration(node);
        }
    }
}
